// pages/person-center/person-center.js
const app = getApp()
const util = require('../../utils/util.js')
const auth = require('../../utils/auth.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo: {},
    hasUserInfo: false, 
    tempRes1:[],
    tempRes2:[],
    tempRes3:[],
    tempRes4:[],
    tempRes5:[],
    tempRes6:[],
    tempRes8:[],
    collectionCards:[],
    empty:'../../images/nocollect.png',
    showEmpty:true,
    show1:false,
    show2:false,
    show3:false,
    show4:false,
    show5:false,
    show6:false,
    show7:false,
    show8:false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
        
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // 在没有 open-type=getUserInfo 版本的兼容处理
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo;
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      });
    var that=this;
    util.ajax({
      url: 'act/actapi/collect_list',
      data: {
         
      },
      header: {
          'content-type': 'application/json' // 默认值
      },
      success: function(res) {
        var res = res.data;
        var tempRes1,tempRes2,tempRes3,tempRes4,tempRes5,tempRes6,tempRes8 = [];
        var tempCard = [];
        var keyArry = [];
        for(var key in res){
          keyArry.push(key);
          if (key == 1) {
            tempRes1=res[1];
          }else if (key == 2) {
            tempRes2=res[2];
          }else if (key == 3) {
            tempRes3=res[3];
          }else if (key == 4) {
            tempRes4=res[4];
          }else if (key == 5) {
            tempRes5=res[5];
          }else if (key == 6) {
            tempRes6=res[6];
          }else if (key == 7) {
            tempCard=res[7];
          }else if (key == 8) {
            tempRes8=res[8];
          }
        }
        if (keyArry.length == 1) {that.setData({showEmpty:false})}else{that.setData({showEmpty:true})}
        if (tempRes1 == undefined || tempRes1.length == 0) {that.setData({show1:true})}else{that.setData({show1:false})}
        if (tempRes2 == undefined || tempRes2.length == 0) {that.setData({show2:true})}else{that.setData({show2:false})}
        if (tempRes3 == undefined || tempRes3.length == 0) {that.setData({show3:true})}else{that.setData({show3:false})}
        if (tempRes4 == undefined || tempRes4.length == 0) {that.setData({show4:true})}else{that.setData({show4:false})}
        if (tempRes5 == undefined || tempRes5.length == 0) {that.setData({show5:true})}else{that.setData({show5:false})}
        if (tempRes6 == undefined || tempRes6.length == 0) {that.setData({show6:true})}else{that.setData({show6:false})}
        if (tempCard == undefined || tempCard.length == 0) {that.setData({show7:true})}else{that.setData({show7:false})}
        if (tempRes8 == undefined || tempRes8.length == 0) {that.setData({show8:true})}else{that.setData({show8:false})}
        // tempRes.pop();
        // console.log(tempRes);
        // for(var i=0;i<tempRes[tempRes.length-1].length;i++){
        //   if (tempRes[tempRes.length-1][i].FTitle == "") {
        //       tempCard.push(tempRes[tempRes.length-1]);
        //       tempRes.splice(tempRes.length-1);
        //     }
        // }
        that.setData({
          tempRes1:tempRes1,
          tempRes2:tempRes2,
          tempRes3:tempRes3,
          tempRes4:tempRes4,
          tempRes5:tempRes5,
          tempRes6:tempRes6,
          tempRes8:tempRes8,
          collectionCards:tempCard,
        });
        // console.log(that.data.tempRes1);
        // console.log(that.data.tempRes2);
        // console.log(that.data.tempRes3);
        // console.log(that.data.tempRes4);
        // console.log(that.data.tempRes5);
        // console.log(that.data.tempRes6);
        // console.log(that.data.collectionCards);
      }
    })  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})